home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2001 May / SGI Freeware 2001 May - Disc 1.iso / dist / fw_mysql.idb / usr / freeware / share / sql-bench / compare-results.z / compare-results
Encoding:
Text File  |  1999-10-18  |  15.1 KB  |  591 lines

  1. #!/bin/perl5
  2. # a little program to generate a table of results
  3. # just read all the RUN-*.log files and format them nicely
  4. # Made by Luuk de Boer
  5. # Patched by Monty
  6.  
  7. use Getopt::Long;
  8.  
  9. $opt_server="mysql";
  10. $opt_dir="output";
  11. $opt_machine="";
  12. $opt_relative=$opt_same_server=$opt_help=$opt_Information=$opt_skip_count=$opt_no_bars=$opt_verbose=0;
  13.  
  14. GetOptions("Information","help","server=s","cmp=s","machine=s","relative","same-server","dir=s","skip-count","no-bars","html","verbose") || usage();
  15.  
  16. usage() if ($opt_help || $opt_Information);
  17.  
  18. $opt_cmp=lc(join(",",sort(split(',',$opt_cmp))));
  19.  
  20. if ($opt_same_server)
  21. {
  22.   $files="$opt_dir/RUN-$opt_server*$opt_machine";
  23. }
  24. else
  25. {
  26.   $files="$opt_dir/RUN-*$opt_machine";
  27. }
  28. $files.= "-cmp-$opt_cmp" if (length($opt_cmp));
  29.  
  30. #
  31. # Go trough all RUN files and gather statistics.
  32. #
  33.  
  34. if ($#ARGV == -1)
  35. {
  36.   @ARGV=glob($files);
  37.   $automatic_files=1;
  38. }
  39. else
  40. {
  41.   $opt_cmp="";
  42. }
  43.  
  44. foreach (@ARGV)
  45. {
  46.   next if (!$opt_cmp && /-cmp-/ && $automatic_files || defined($found{$_}));
  47.   $prog=$filename = $_;
  48.   $found{$_}=1;            # Remove dupplicates
  49.   /RUN-(.*)$/;
  50.   $tot{$prog}{'version'}=$1;
  51.   push(@key_order,$prog);
  52.   $next = 0;
  53.   open(TMP, "<$filename") || die "Can't open $filename: $!\n";
  54.   while (<TMP>)
  55.   {
  56.     chomp;
  57.     if ($next == 0) {
  58.       if (/Server version:\s+(\S+.*)/i)
  59.       {
  60.     $tot{$prog}{'server'} = $1;
  61.       }
  62.       elsif (/Arguments:\s+(.+)/i)
  63.       {
  64.     $arguments= $1;
  65.     # Remove some standard, not informative arguments
  66.     $arguments =~ s/--force|--log|--use-old\S*|--server=\S+|--cmp=\S+|--user=\S+|--pass=\S+|--machine=\S+|--dir=\S+//g;
  67.     if (($tmp=index($arguments,"--comment")) >= 0)
  68.     {
  69.       if (($end=index($arguments,$tmp+2,"--")) >= 0)
  70.       {
  71.         substr($arguments,$tmp,($end-$tmp))="";
  72.       }
  73.       else
  74.       {
  75.         $arguments=substr($arguments,0,$tmp);
  76.       }
  77.     }
  78.     $arguments =~ s/\s+/ /g;
  79.     $tot{$prog}{'arguments'}=$arguments;
  80.       }
  81.       elsif (/Comments:\s+(.+)/i) {
  82.     $tot{$prog}{'comments'} = $1;
  83.       } elsif (/^(\S+):\s*(estimated\s|)total\stime:\s+(\d+)\s+(wallclock\s|)secs/i)
  84.       {
  85.     $tmp = $1; $tmp =~ s/://;
  86.     $tot{$prog}{$tmp} = [ $3, (length($2) ? "+" : "")];
  87.     $op1{$tmp} = $tmp;
  88.       } elsif (/Totals per operation:/i) {
  89.     $next = 1;
  90.     next;
  91.       }
  92.     }
  93.     elsif ($next == 1)
  94.     {
  95.       if (/^(\S+)\s+(\d+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)\s*([+|?])*/)
  96.       {
  97.     $tot1{$prog}{$1} = [$2,$6,$7];
  98.     $op{$1} = $1;
  99.       }
  100.     }
  101.   }
  102. }
  103.  
  104. if (!%op)
  105. {
  106.   print "Didn't find any files matching: '$files'\n";
  107.   print "Use the --cmp=server,server option to compare benchmarks\n";
  108.   exit 1;
  109. }
  110.  
  111.  
  112. # everything is loaded ...
  113. # now we have to create a fancy output :-)
  114.  
  115. # I prefer to redirect scripts instead to force it to file ; Monty
  116. #
  117. # open(RES, ">$resultfile") || die "Can't write to $resultfile: $!\n";
  118. # select(RES)
  119. #
  120.  
  121. if ($opt_html) {
  122.   html_output();
  123. } else {
  124.   ascii_output();
  125. }
  126. exit 0;
  127.  
  128. #
  129. # some output + format functions;
  130. #
  131.  
  132. sub ascii_output {
  133.   print <<EOF;
  134. This is the result file of the different benchmark tests.
  135.  
  136. The number in () after each tests shows how many SQL commands the particular
  137. test did.  As one test may have many different parameters this gives only
  138. a rough picture of what was done.  Check the source for more information :)
  139.  
  140. Keep in mind that one can\'t compare benchmarks run with different --cmp
  141. options. The --cmp options sets the all limits according to the worst
  142. limit for all server in the benchmark.
  143.  
  144. Numbers marked with '+' are estimated according to previous runs because
  145. the query took longer than a given time-limit to finish. The estimation
  146. shouldn\'t be far from the real result thought.
  147.  
  148. Numbers marked with '?' contains results that gave wrong result. This can only
  149. be used as an indication of how long it took for the server to produce a wrong
  150. result :)
  151.  
  152. Numbers marked with '*' are tests that was run a different number times
  153. than the test in the first column.  The reason for this is normally that the
  154. marked test was run with different options that affects the number of tests
  155. or that the test was from another version of the MySQL benchmarks.
  156.  
  157. Hope this will give you some idea how each db is performing at what thing ....
  158. Hope you like it .... Luuk & Monty (1997)
  159.  
  160. EOF
  161.  
  162.   if ($opt_relative)
  163.   {
  164.     print "Column 1 is in seconds. All other columns are presented relative\n";
  165.     print "to this. 1.00 is the same, bigger numbers indicates slower\n\n";
  166.   }
  167.  
  168.   if ($opt_verbose)
  169.   {
  170.     print "The test values is printed in the format 'time:number of tests'\n";
  171.   }
  172.  
  173.   if (length($opt_cmp))
  174.   {
  175.     print "The test was run with limits from: $opt_cmp\n\n";
  176.   }
  177.   print "The result logs which where found and the options:\n";
  178.   $bar= $opt_no_bars ? " " : "|";
  179.  
  180.   # Move $opt_server first in array if not filename on command line
  181.   if ($automatic_files)
  182.   {
  183.     @key_order=sort {$a cmp $b} keys %tot;
  184.     for ($i=0; $i <= $#key_order; $i++)
  185.     {
  186.       if ($tot{$key_order[$i]}{'version'} =~ /^$opt_server-/)
  187.       {
  188.     unshift(@key_order,$key_order[$i]);
  189.     splice(@key_order,$i+1,1);
  190.     last;
  191.       }
  192.     }
  193.   }
  194.   # Print header
  195.  
  196.   $column_count=0;
  197.   foreach $key (@key_order)
  198.   {
  199.     $tmp=$tmp=$tot{$key}{'version'};
  200.     $tmp =~ s/-cmp-$opt_cmp// if (length($opt_cmp));
  201.     $column_count++;
  202.     printf "%2d %-40.40s: %s %s\n", $column_count, $tmp,
  203.     $tot{$key}{'server'}, $tot{$key}{'arguments'};
  204.     print "  $tot{$key}{'comments'}\n"
  205.       if ($tot{$key}{'comments'} =~ /\w+/);
  206.   }
  207.  
  208.   print "\n";
  209.  
  210.   $namewidth=($opt_skip_count && !$opt_verbose) ? 22 :29;
  211.   $colwidth= $opt_relative ? 10 : 7;
  212.   $count_width=7;
  213.   $colwidth+=$count_width if ($opt_verbose);
  214.  
  215.   print_sep("=");
  216.   printf "%-$namewidth.${namewidth}s${bar}", "Operation";
  217.   $count = 1;
  218.   foreach $key (@key_order)
  219.   {
  220.     printf "%${colwidth}d${bar}", $count;
  221.     $count++;
  222.   }
  223.   printf "\n%-$namewidth.${namewidth}s${bar}", "";
  224.   foreach $key (@key_order)
  225.   {
  226.     $ver=$tot{$key}{'version'};
  227.     $ver =~ s/-[a-zA-Z0-9_\.]+-cmp-$opt-cmp$//;
  228.     printf "%${colwidth}.${colwidth}s${bar}", $ver;
  229.   }
  230.   print "\n";
  231.   print_sep("-");
  232.   print_string($opt_relative ? "Relative results per test (First column is in seconds):" : "Results per test in seconds:");
  233.   print_sep("-");
  234.  
  235.   foreach $key (sort {$a cmp $b} keys %op1)
  236.   {
  237.     printf "%-$namewidth.${namewidth}s${bar}", $key;
  238.     $first=undef();
  239.     foreach $server (@key_order)
  240.     {
  241.       print_value($first,$tot{$server}{$key}->[0],undef(),$tot{$server}{$key}->[1]);
  242.       $first=$tot{$server}{$key}->[0] if (!defined($first));
  243.     }
  244.     print "\n";
  245.   }
  246.  
  247.   print_sep("-");
  248.   print_string("The results per operation:");
  249.   print_sep("-");
  250.  
  251.   foreach $key (sort {$a cmp $b} keys %op)
  252.   {
  253.     next if ($key =~ /TOTALS/i);
  254.     $tmp=$key;
  255.     $count=$tot1{$key_order[0]}{$key}->[1];
  256.     $tmp.= " (" . $count .  ")" if (!$skip_count);
  257.     printf "%-$namewidth.${namewidth}s${bar}", $tmp;
  258.     $first=undef();
  259.     foreach $server (@key_order)
  260.     {
  261.       $tmp= $count != $tot1{$server}{$key}->[1] ? "*" : "";
  262.       print_value($first,$tot1{$server}{$key}->[0],$tot1{$server}{$key}->[1],
  263.           $tot1{$server}{$key}->[2] . $tmp);
  264.       $first=$tot1{$server}{$key}->[0] if (!defined($first));
  265.     }
  266.     print "\n";
  267.   }
  268.  
  269.   print_sep("-");
  270.   $key="TOTALS";
  271.   printf "%-$namewidth.${namewidth}s${bar}", $key;
  272.   $first=undef();
  273.   foreach $server (@key_order)
  274.   {
  275.     print_value($first,$tot1{$server}{$key}->[0],undef(),
  276.         $tot1{$server}{$key}->[2]);
  277.     $first=$tot1{$server}{$key}->[0] if (!defined($first));
  278.   }
  279.   print "\n";
  280.   print_sep("=");
  281. }
  282.  
  283.  
  284. sub html_output
  285. {
  286.   my $template="template.html";
  287.   my $title="MySQL Benchmark Results - Compare with $opt_cmp";
  288.   my $image="info.gif";
  289.   $bar="";
  290.  
  291.   open(TEMPLATE, $template) || die;
  292.   while (<TEMPLATE>)
  293.   {
  294.     if (/<center>/)
  295.     {
  296.       print $_;
  297.       print "<!---- This is AUTOMATICALLY Generated. Do not edit here! ---->\n";
  298.     }
  299.     elsif (/TITLE:SUBTITLE/)
  300.     {
  301.       s|TITLE:SUBTITLE|$title|;
  302.       print $_;
  303.     }
  304.     elsif (m|/images/.gif|)
  305.     {
  306.       s|/images/.gif|/images/$image|;
  307.       s|alt=""|alt="$title"|;
  308.       print $_;
  309.     }
  310.     # Find line to inactivate
  311.     elsif (m|<img src="/images/${text}1.gif" border="0" width="66" height="20" alt="$text">|)
  312.     {
  313.       # Print inactive thing
  314.       print '<td align="center" bgcolor="#310063"><img src="/images/zero.gif" border="0" width="66" height="20" alt=""></td>';
  315.     }
  316.     elsif (/ subchapter name /)
  317.     {
  318.       # Nothing here for now
  319.       print $_;
  320.     }
  321.     elsif (/ text of chapter /)
  322.     {
  323.       print $_;
  324.       print_html_body();
  325.     }
  326.     else
  327.     {
  328.       print $_;
  329.     }
  330.   }
  331.   close(TEMPLATE);
  332. }
  333.  
  334.  
  335. sub print_html_body
  336. {
  337.   my ($title,$count,$key);
  338.   print <<EOF;
  339. <center>
  340. <font size=+4><b>MySQL Benchmark Results</b></font><br>
  341. <font size=+1><b>Compare with $opt_cmp</b></font><p><p>
  342. </center>
  343. This is the result file of the different benchmark tests.
  344. <p>
  345.  
  346. The number in () after each tests shows how many SQL commands the particular
  347. test did.  As one test may have many different parameters this gives only
  348. a rough picture of what was done.  Check the source for more information.
  349. <p>
  350. Keep in mind that one can\'t compare benchmarks run with different --cmp
  351. options. The --cmp options sets the all limits according to the worst
  352. limit for all server in the benchmark.
  353. <p>
  354. Numbers marked with '+' are estimated according to previous runs because
  355. the query took longer than a given time-limit to finish. The estimation
  356. shouldn\'t be far from the real result thought.
  357. <p>
  358. Numbers marked with '?' contains results that gave wrong result. This can only
  359. be used as an indication of how long it took for the server to produce a wrong
  360. result :)
  361. <p>
  362. Hope this will give you some idea how each db is performing at what thing ....
  363. <br>
  364. Hope you like it .... Luuk & Monty (1997)
  365. <p><p>
  366. EOF
  367.  
  368.   if ($opt_relative)
  369.   {
  370.     print "Column 1 is in seconds. All other columns are presented relative<br>\n";
  371.     print "to this. 1.00 is the same, bigger numbers indicates slower<p>\n\n";
  372.   }
  373.  
  374.   if (length($opt_cmp))
  375.   {
  376.     print "The test was run with limits from: $opt_cmp\n\n";
  377.   }
  378.   print "The result logs which where found and the options:<br>\n";
  379.  
  380.   # Move $opt_server first in array
  381.   if ($automatic_files)
  382.   {
  383.     @key_order=sort {$a cmp $b} keys %tot;
  384.     for ($i=0; $i <= $#key_order; $i++)
  385.     {
  386.       if ($tot{$key_order[$i]}{'version'} =~ /^$opt_server-/)
  387.       {
  388.     unshift(@key_order,$key_order[$i]);
  389.     splice(@key_order,$i+1,1);
  390.     last;
  391.       }
  392.     }
  393.   }
  394.   # Print header
  395.   print "<p><center><table border=1 width=100%>\n";
  396.   $column_count=0;
  397.   foreach $key (@key_order)
  398.   {
  399.     $tmp=$tot{$key}{'version'};
  400.     $tmp =~ s/-cmp-$opt_cmp// if (length($opt_cmp));
  401.     $column_count++;
  402. #    printf "<tr><td>%2d<td>%-30.30s<td>%s %s</tr>\n", $column_count, $tmp,
  403.     printf "<tr><td>%2d</td><td>%s</td><td>%s %s</td></tr>\n",
  404.     $column_count, $tmp, $tot{$key}{'server'}, $tot{$key}{'arguments'};
  405.     print "<tr><td colspan=3>$tot{$key}{'comments'}</td></tr>\n"
  406.       if ($tot{$key}{'comments'} =~ /\w+/);
  407.   }
  408.  
  409.   print "</table></center><p><center><table border=1 width=100%>\n";
  410.  
  411.   $namewidth=$opt_skip_count ? 22 :29;
  412.   $colwidth= $opt_relative ? 10 : 7;
  413.   $count_width=7;
  414.  
  415.   printf "<tr><td><b>%s</b></td>\n", "Operation";
  416.   $count = 1;
  417.   foreach $key (@key_order)
  418.   {
  419.     $ver=$tot{$key}{'version'};
  420.     printf "<td align=center><b>%d", $count;
  421.     printf "<br>%${colwidth}.${colwidth}s</b></td>\n", substr($ver,0,index($ver,"-"));
  422.     $count++;
  423.   }
  424.   print "</tr>\n";
  425.   $title = $opt_relative ? "Relative results per test (First column is in seconds):" : "Results per test in seconds:";
  426.   printf "<tr><td colspan=%d><b>%s</b></td></tr>\n", $count, $title;
  427.  
  428.   foreach $key (sort {$a cmp $b} keys %op1)
  429.   {
  430.     printf "<tr><td>%-$namewidth.${namewidth}s</td>", $key;
  431.     $first=undef();
  432.     foreach $server (@key_order)
  433.     {
  434.       print_value($first,$tot{$server}{$key}->[0],undef(),
  435.           $tot{$server}{$key}->[1]);
  436.       $first=$tot{$server}{$key}->[0] if (!defined($first));
  437.     }
  438.     print "</tr>\n";
  439.   }
  440.  
  441.   $title = "The results per operation:";
  442.   printf "<tr><td colspan=%d><b>%s</b></td></tr>\n", $count, $title;
  443.  
  444.   foreach $key (sort {$a cmp $b} keys %op)
  445.   {
  446.     next if ($key =~ /TOTALS/i);
  447.     $tmp=$key;
  448.     $tmp.= " (" . $tot1{$key_order[0]}{$key}->[1] . ")" if (!$skip_count);
  449.     printf "<tr><td>%-$namewidth.${namewidth}s</td>", $tmp;
  450.     $first=undef();
  451.     foreach $server (@key_order)
  452.     {
  453.       print_value($first,$tot1{$server}{$key}->[0],
  454.           $tot1{$server}{$key}->[1],
  455.           $tot1{$server}{$key}->[2]);
  456.       $first=$tot1{$server}{$key}->[0] if (!defined($first));
  457.     }
  458.     print "</tr>\n";
  459.   }
  460.  
  461.   $key="TOTALS";
  462.   printf "<tr><td><b>%-$namewidth.${namewidth}s</b></td>", $key;
  463.   $first=undef();
  464.   foreach $server (@key_order)
  465.   {
  466.     print_value($first,$tot1{$server}{$key}->[0],undef(),
  467.         $tot1{$server}{$key}->[2]);
  468.     $first=$tot1{$server}{$key}->[0] if (!defined($first));
  469.   }
  470.   print "</tr>\n</table>\n";
  471. }
  472.  
  473.  
  474. sub print_sep
  475. {
  476.   my ($sep)=@_;
  477.   print $sep x ($namewidth + (($colwidth+1) * $column_count)+1),"\n";
  478. }
  479.  
  480.  
  481. sub print_value
  482. {
  483.   my ($first,$value,$count,$flags)=@_;
  484.   my ($tmp,$width);
  485.  
  486.   if (defined($value))
  487.   {
  488.     if (!defined($first) || !$opt_relative)
  489.     {
  490.       $tmp=sprintf("%d",$value);
  491.     }
  492.     else
  493.     {
  494.       $first=1 if (!$first);    # Assume that it took one second instead of 0
  495.       $tmp= sprintf("%.2f",$value/$first);
  496.     }
  497.     if (defined($flags))
  498.     {
  499.       $tmp="+".$tmp if ($flags =~ /\+/);
  500.       $tmp="?".$tmp if ($flags =~ /\?/);
  501.       $tmp="*".$tmp if ($flags =~ /\*/);
  502.     }
  503.   }
  504.   else
  505.   {
  506.     $tmp="";
  507.   }
  508.   $width= ($opt_verbose ? $colwidth - $count_width : $colwidth);
  509.   $tmp= " " x ($width-length($tmp)) . $tmp if (length($tmp) < $width);
  510.   if ($opt_verbose)
  511.   {
  512.     if ($count)
  513.     {
  514.       $tmp.= ":" . " " x ($count_width-1-length($count)) . $count;
  515.     }
  516.     else
  517.     {
  518.       $tmp.= " " x ($count_width);
  519.     }
  520.   }
  521.  
  522.   if (!$opt_html) {
  523.     print $tmp . "${bar}";
  524.   } else {
  525.     print "<td align=right>$tmp</td>";
  526.   }
  527. }
  528.  
  529.  
  530. sub print_string
  531. {
  532.   my ($str)=@_;
  533.   my ($width);
  534.   $width=$namewidth + ($colwidth+1)*$column_count;
  535.  
  536.   $str=substr($str,1,$width) if (length($str) > $width);
  537.   print($str," " x ($width - length($str)),"${bar}\n");
  538. }
  539.  
  540.  
  541. sub usage
  542. {
  543.     print <<EOF;
  544. $0  Ver 1.1
  545.  
  546. This program parses all RUN files from old 'run-all-tests --log' scripts
  547. and makes a nice comparable table.
  548.  
  549. $0 takes currently the following options:
  550.  
  551. --help or --Information        
  552.   Shows this help
  553.  
  554. --cmp=server,server,server (Default $opt_cmp)
  555. Compares all runs that are done with the same --cmp options to run-all-tests.
  556. The most normal options are '--cmp=mysql,pg,solid' and '--cmp ""'
  557.  
  558. --dir=...  (Default $opt_dir)
  559. From which directory one should get the runs.  All runs made by
  560. run-all-tests --log is saved in the 'output' directory.
  561. In the 'results' directory you may have some example runs from different
  562. databases.
  563.  
  564. --html
  565.   Print the table in html format.
  566.  
  567. --machine='full-machine-name' (Default $opt_machine)
  568. Use only runs that match this machine.
  569.  
  570. --relative
  571. Show all numbers in times of the first server where the time for the
  572. first server is 1.0
  573.  
  574. --same-server
  575. Compare all runs for --server=....  The --machine is not used in this case
  576. This is nice to compare how the same server runs on different machines.
  577.  
  578. --server='server name'  (Default $opt_server)
  579. Put this server in the first result column.
  580.  
  581. --skip-count
  582. Do not write the number of tests after the test-name.
  583.  
  584. --verbose
  585. Write the number of tests in each column. This is useful when some column
  586. is marked with '*'.
  587. EOF
  588.  
  589.   exit(0);
  590. }
  591.